package com.frejoys.app.controller;

import com.frejoys.common.aop.Authority;
import com.frejoys.common.aop.Authorization;
import com.frejoys.common.constant.CommonConstant;
import com.frejoys.common.dto.app.CategoryIdDto;
import com.frejoys.common.dto.app.CodeDto;
import com.frejoys.common.dto.store.StoreLngAndTelDto;
import com.frejoys.common.response.Result;
import com.frejoys.common.vo.app.StoreListInfoVo;
import com.frejoys.common.vo.app.StoreVo;
import com.frejoys.common.vo.store.StoreListVo;
import com.frejoys.service.StoreCodeService;
import com.frejoys.service.StoreService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
@Tag(name = "店铺", description = "店铺")
@RestController
@RequiredArgsConstructor
@RequestMapping(CommonConstant.routePrefixApp)
@Authorization(Authority.Private)
public class StoreController {

    private final StoreService storeService;

    private final StoreCodeService storeCodeService;

    @Authorization(Authority.Protected)
    @PostMapping("/store/storeAppListInfo")
    @Operation(summary = "主页店铺列表 推荐/附近")
    public Result<List<StoreListVo>> storeAppListInfo(@RequestBody @Validated StoreLngAndTelDto storeLngAndTelDto){
        return Result.success(storeService.storeAppListInfo(storeLngAndTelDto));
    }

    @Authorization(Authority.Protected)
    @PostMapping("/store/storeDetails")
    @Operation(summary = "店铺详情页")
    public Result<StoreVo> storeDetails(@RequestBody @Validated CodeDto dto){
        if (dto.getCode() != null){
            Integer storeId = storeCodeService.getStoreId(dto.getCode());
            dto.setId(storeId);
        }
        return Result.success(storeService.storeDetails(dto));
    }


    @Authorization(Authority.Protected)
    @PostMapping("/store/categoryIdStoreListInfo")
    @Operation(summary = "查询店铺列表")
    public Result<List<StoreListInfoVo>> categoryIdStoreListInfo(@RequestBody @Validated CategoryIdDto dto){
        return Result.success(storeService.categoryIdStoreList(dto));
    }

}
